package cn.edu.ldu.modules.controller;

import cn.edu.ldu.http.rqtUtils;
import cn.edu.ldu.modules.entity.UserEntity;
import cn.edu.ldu.util.Consts;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

public class LoginController {

    @ResponseBody
    public static String login(@RequestBody UserEntity user){

        String jsonObject = JSONObject.toJSONString(user);
        try {
            String jsonString = rqtUtils.httpclientPost(new StringBuffer(Consts.userLogin), jsonObject, null);
            return jsonString!= null ? JSON.parseObject(jsonString).getString("token") : null;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
